package com.jlnk.stockdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.jlnk.stockdemo.R;
import com.jlnk.stockdemo.bean.FutureListResponse;

import java.util.List;

public class FutureAdapter extends RecyclerView.Adapter<FutureAdapter.FutureViewHolder> {
    private List<FutureListResponse.Data.Future> futureItems;

    public FutureAdapter(List<FutureListResponse.Data.Future> futureItems) {
        this.futureItems = futureItems;
    }

    @Override
    public FutureViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_future_list, parent, false);
        return new FutureViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(FutureViewHolder holder, int position) {
        FutureListResponse.Data.Future futureItem = futureItems.get(position);
        holder.tv_symbol.setText((String) futureItem.getSymbol());
        holder.tv_name.setText((String) futureItem.getName());
        holder.tv_quote_unit.setText((String) futureItem.getQuote_unit());
        holder.tv_d_mode_desc.setText((String) futureItem.getD_mode_desc());
        holder.tv_last_ddate.setText((String) futureItem.getLast_ddate());

    }

    @Override
    public int getItemCount() {
        return futureItems.size();
    }

    public static class FutureViewHolder extends RecyclerView.ViewHolder {
        TextView tv_symbol;
        TextView tv_name;
        TextView tv_quote_unit;
        TextView tv_d_mode_desc;
        TextView tv_last_ddate;

        public FutureViewHolder(View itemView) {
            super(itemView);
            tv_symbol = itemView.findViewById(R.id.tv_symbol);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_quote_unit = itemView.findViewById(R.id.tv_quote_unit);
            tv_d_mode_desc = itemView.findViewById(R.id.tv_d_mode_desc);
            tv_last_ddate = itemView.findViewById(R.id.tv_last_ddate);
        }
    }
}
